package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.query.StrategyCatalogQuery;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/strategyCatalog")
@Controller
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;


    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") StrategyCatalogQuery qo){
        //根据请求查询分页数据
        Page<StrategyCatalog> page = strategyCatalogService.query(qo);
        //加到模型中
        model.addAttribute("page", page);
        return "strategyCatalog/list";
    }


    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        //调用服务层方法
        if (StringUtils.hasLength(strategyCatalog.getId())){
            //调用更新方法
            strategyCatalogService.update(strategyCatalog);
        }else {
            //调用保存方法
            strategyCatalogService.save(strategyCatalog);
        }
        //返回执行成功
        return JsonResult.success();
    }





    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){
        //删除
        strategyCatalogService.deleteById(id);
        //返回jsonresult
        return JsonResult.success();
    }

}
